package com.jt.tenant.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jt.tenant.R;
import com.jt.tenant.adapter.OrderSureAdapter;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.conn.GetProductQuery;
import com.jt.tenant.widget.MyListView;
import com.jt.tenant.widget.Tools;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class OrderSureActivity extends JTActivity implements View.OnClickListener {

    private String name,phone,id,img,money,order_id;

    private TextView mTitleText,tv_next;

    private TextView mMaintainName,mMaintainTel;

    private ImageView mMaintainImg;

    private MyListView mShopListView;

    private List<GetProductQuery.NameList> mList = new ArrayList<>();

    private OrderSureAdapter mAdapter;

    private TextView mMoneyText;

    private TextView mOrderNumText,mTelText,mOrderTime;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_sure);

        getData();

        initView();
    }

    private void getData(){

        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        name = bundle.getString("name");
        phone = bundle.getString("phone");
        id = bundle.getString("id");
        img = bundle.getString("img");
        money = bundle.getString("money");
        mList.addAll((Collection<? extends GetProductQuery.NameList>) bundle.getSerializable("list"));


    }

    private void initView(){

        mTitleText = (TextView) findViewById(R.id.tv_title_name);

        mTitleText.setText("确认订单");

        (tv_next = (TextView)findViewById(R.id.text_order_commit)).setOnClickListener(this);

        mMaintainName = (TextView) findViewById(R.id.text_maintain_name);

        mMaintainName.setText(name);

        mMaintainTel = (TextView) findViewById(R.id.text_maintain_tel);

        mMaintainTel.setText("商家电话:"+phone);

        mMaintainImg = (ImageView) findViewById(R.id.img_maintain_shop);

        JTApplication.UtilAsyncBitmap.get(img,mMaintainImg);

        mShopListView = (MyListView) findViewById(R.id.list_order_sure);

        mAdapter = new OrderSureAdapter(this,mList);

        mShopListView.setAdapter(mAdapter);

        mMoneyText = (TextView)findViewById(R.id.text_order_money);

        mMoneyText.setText("￥" + Tools.F_num(money));

        mOrderNumText = (TextView) findViewById(R.id.text_order_num);

        order_id = "jtOID"+System.currentTimeMillis();

        mOrderNumText.setText("订单编号："+order_id);

        mOrderTime = (TextView) findViewById(R.id.text_order_time);

        mOrderTime.setText("下单时间："+Tools.getTime1(String.valueOf(System.currentTimeMillis())));

        mTelText = (TextView) findViewById(R.id.text_order_tel);

        mTelText.setText("联系方式 : " + JTApplication.jtPreferences.readPhone());


    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){

            case R.id.text_order_commit:

                startActivity(new Intent(this,GSPaymentActivity.class)

                        .putExtra("order_id",order_id)

                        .putExtra("total_price",Tools.F_num(money))

                );

                break;

        }
    }
}
